package com.dianneng.show.model;

import com.dianneng.show.util.CommonUtil;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

public class MonthInfo extends BaseResult implements Serializable {


    private List<DataBean> data;

    public List<DataBean> getData() {
        return data;
    }

    public void setData(List<DataBean> data) {
        this.data = data;
    }

    public static class DataBean {
        /**
         * sn : null
         * eq : 26
         * vtA : null
         * vtB : null
         * vtC : null
         * ecA : null
         * ecB : null
         * ecC : null
         * ap : null
         * apA : null
         * apB : null
         * apC : null
         * awp : null
         * awpA : null
         * awpB : null
         * awpC : null
         * pf : null
         * pfA : null
         * pfB : null
         * pfC : null
         * hz : null
         * createtime : 2019-07-16 00:00:00
         */

        private float eq;
        private String createtime;
        private int index;

        public int getMonth(){
            int m=Integer.valueOf(CommonUtil.getTime12(createtime));
            return m;
        }

        public int getDay(){
            return Integer.valueOf(CommonUtil.getTime10(createtime));
        }

        public int getYear(){
            return  Integer.valueOf(CommonUtil.getTime13(createtime));
        }

        public int getIndex() {
            index= Integer.valueOf(CommonUtil.getTime10(createtime))-1;
            return index;
        }

        public void setIndex(int index) {
            this.index = index;
        }


        public float getEq() {
            return eq;
        }

        public void setEq(float eq) {
            this.eq = eq;
        }

        public String getCreatetime() {
            return createtime;
        }

        public void setCreatetime(String createtime) {
            this.createtime = createtime;
        }
    }

    public static List<DataBean> getLineData(List<DataBean> input){

        List<DataBean> output=new ArrayList<>();
        if (input.isEmpty()){
            for (int i=0;i<31;i++){
                DataBean dataBean=new DataBean();
                dataBean.setIndex(i);
                dataBean.setEq(0);
                output.add(dataBean);
            }
            return output;
        }

        int year=input.get(0).getYear();
        int month=input.get(0).getMonth();

        List<Integer> day31=new ArrayList<>();
        day31.add(1);
        day31.add(3);
        day31.add(5);
        day31.add(7);
        day31.add(8);
        day31.add(10);
        day31.add(12);

        float[] tmp=new float[31];
        for (int i=0;i<tmp.length;i++){
            tmp[i]=0;
        }
        for (DataBean dataBean:input){
            tmp[dataBean.getIndex()]=dataBean.getEq()/100f;
        }

        for (int i=0;i<tmp.length;i++){
            if (i>0){
                tmp[i]=tmp[i]+tmp[i-1];
            }
            DataBean dataBean=new DataBean();
            dataBean.setIndex(i);
            if (!day31.contains(month) && i==30){
                dataBean.setEq(0);
            }else if (year==CommonUtil.getCurrentYear() && month==CommonUtil.getOneMonth()&& i>=CommonUtil.getCurrentDay()){
                dataBean.setEq(0);
            }else {
                dataBean.setEq(tmp[i]);
            }
            output.add(dataBean);
        }



        return output;
    }

    public static List<DataBean> getBarData(List<DataBean> input){
        List<DataBean> output=new ArrayList<>();

        float[] tmp=new float[31];
        for (int i=0;i<tmp.length;i++){
            tmp[i]=0;
        }
        for (DataBean dataBean:input){
            tmp[dataBean.getIndex()]=dataBean.getEq()/100f;
        }
        for (int i=0;i<tmp.length;i++){
            DataBean dataBean=new DataBean();
            dataBean.setIndex(i);
            dataBean.setEq(tmp[i]);
            output.add(dataBean);
        }
        return output;
    }
}
